const initState = {
  todolist: [
    { id: 0, title: '吃饭' },
    { id: 1, title: '睡觉' },
    { id: 2, title: '睁眼' },
  ],
}

export default function todolist(state = initState, { type, payload }) {
  switch (type) {
    case 'addEvent':
      return {
        todolist: [
          ...state.todolist,
          {
            id: state.todolist.length + 1,
            title: payload,
          },
        ],
      }
    case 'delFun':
      state.todolist.splice(payload, 1)
      return {
        todolist: [...state.todolist],
      }
    default:
      return state
  }
}
